<template>
  <page-header-wrapper :title="title">
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="4" :sm="24">
              <a-form-item>
                <a-input placeholder="请输入手机号" v-model="queryParam.mobile" />
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="handleSearch(true)" icon="search">查询</a-button>
              </span>
            </a-col>
            <a-col :md="1" :sm="24" :offset="14" v-if="dataSource">
              <a-button type="primary" @click="$emit('back')">返回</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
        :pagination="pagination"
      >
        <template slot="head_img" slot-scope="text">
          <a-avatar shape="square" :size="64" icon="user" :src="text" />
        </template>
        <a-tag :color="text == 1 ? 'blue' : 'red'" slot="is_vip" slot-scope="text">{{ text | statusFilter }}</a-tag>
        <a-tag :color="text == 1 ? 'blue' : 'red'" slot="is_card" slot-scope="text">{{ text | statusFilter }}</a-tag>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { inviteUser } from '@/api/store'
import formTableMixin from '@/mixins/formTableMixin'
const columns = [
  {
    title: '昵称',
    dataIndex: 'name'
  },
  {
    title: '头像',
    dataIndex: 'head_img',
    scopedSlots: { customRender: 'head_img' }
  },
  {
    title: '手机号',
    dataIndex: 'mobile'
  },
  {
    title: '是否是会员',
    dataIndex: 'is_vip',
    scopedSlots: { customRender: 'is_vip' }
  },
  {
    title: '是否是年卡',
    dataIndex: 'is_card',
    scopedSlots: { customRender: 'is_card' }
  },
  {
    title: '消费金额',
    dataIndex: 'expend_money',
    customRender (text) {
      return '￥' + text
    }
  },
  {
    title: '下单量',
    dataIndex: 'order_number'
  }
]

const STATUS = {
  1: '是',
  0: '否'
}

export default {
  name: 'InviteUser',
  mixins: [formTableMixin],
  props: {
    dataSource: {
      type: Function,
      default: null
    }
  },
  data () {
    this.columns = columns
    this.listAction = this.dataSource || inviteUser
    return {
      title: ''
    }
  },
  filters: {
    statusFilter (key) {
      return STATUS[key]
    }
  }
}
</script>
